package com.formula.datastructure.exam.sort;

import com.formula.datastructure.util.DataUtil;

public class SelectSort {

    public Integer[] sort(Integer[] array) {
        int N = array.length;
        Integer min;
        int idx;
        for (int i = 0; i < N; i++) {
            idx = i;
            min = array[i];
            for (int j = i; j < N; j++) {
                if (array[j] < min) {
                    min = array[j];
                    idx = j;
                }
            }
            if (idx != i) {
                array[idx] = array[i];
                array[i] = min;
            }
        }
        return array;
    }

    public static void main(String[] args) {
        SelectSort select = new SelectSort();

        int size = 20;
        int range = 999;
        Integer[] array = DataUtil.genUniqueArray(size, range);
        DataUtil.printIndex(size);
        DataUtil.printArray(array);
        DataUtil.printArray(select.sort(array));
    }
}
